---
title: Spec - howl.BufferLines
tags: spec
---
<div class="spec-group spec-group-1">

<h1 id="howl.bufferlines">howl.BufferLines</h1>

<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">text</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="k">with</span><span class="w"> </span><span class="nc">Buffer</span><span class="w"> </span><span class="p">{}</span><span class="w">
    </span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">text</span></code></pre>


<h4 id="#-operator-returns-number-of-lines-in-the-buffer"># operator returns number of lines in the buffer</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'hello\n  world\nagain!'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="o">#</span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span></code></pre>


<h4 id="at_pos(pos)-returns-the-line-at-&lt;pos&gt;">at_pos(pos) returns the line at &lt;pos&gt;</h4>

<pre class="highlight moonscript"><code><span class="n">lines</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="p">(</span><span class="s1">'Øne\ntwØ\nthree'</span><span class="p">).</span><span class="n">lines</span><span class="w">
</span><span class="n">line</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">lines</span><span class="o">\</span><span class="n">at_pos</span><span class="w"> </span><span class="mi">5</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'twØ'</span><span class="p">,</span><span class="w"> </span><span class="n">line</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id="supports-iterating-using-ipairs">supports iterating using ipairs</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'one\ntwo\nthree'</span><span class="w">
</span><span class="k">for</span><span class="w"> </span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="n">line</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="nb">ipairs</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">line</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="n">i</span><span class="p">]</span></code></pre>


<h4 id="supports-iterating-using-pairs">supports iterating using pairs</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'one\ntwo\nthree'</span><span class="w">
</span><span class="k">for</span><span class="w"> </span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="n">line</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="nb">pairs</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="w">
  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">line</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="n">i</span><span class="p">]</span></code></pre>

<div class="spec-group spec-group-2">

<h2 id="line-objects">Line objects</h2>

<pre class="highlight moonscript"><code><span class="kd">local</span><span class="w"> </span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="n">lines</span><span class="w">

</span><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">buf</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'hƏllØ\n  wØrld\nagain!'</span><span class="w">
  </span><span class="n">lines</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">lines</span></code></pre>


<h4 id=".buffer-points-to-the-corresponding-buffer">.buffer points to the corresponding buffer</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="n">buf</span><span class="p">,</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">buffer</span></code></pre>


<h4 id=".nr-holds-the-line-number">.nr holds the line number</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">nr</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span></code></pre>


<h4 id=".text-returns-the-text-of-the-specified-line,-sans-linebreak">.text returns the text of the specified line, sans linebreak</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'hƏllØ'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'  wØrld'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">3</span><span class="p">].</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'again!'</span></code></pre>


<h4 id=".size-is-the-size-of-the-line,-sans-linebreak">.size is the size of the line, sans linebreak</h4>

<pre class="highlight moonscript"><code><span class="n">lines</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="p">(</span><span class="s1">'åäö\n123\n'</span><span class="p">).</span><span class="n">lines</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">6</span><span class="p">,</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">size</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">size</span></code></pre>


<h4 id="tostring(line)-gives-the-same-as-.text">tostring(line) gives the same as .text</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="nb">tostring</span><span class="p">(</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">text</span></code></pre>


<h4 id=".start_pos-returns-the-start-position-for-line">.start_pos returns the start position for line</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">start_pos</span><span class="p">,</span><span class="w"> </span><span class="mi">7</span><span class="w">
</span><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">''</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">start_pos</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span></code></pre>


<h4 id=".end_pos-returns-the-end-position-for-line,-right-before-the-newline">.end_pos returns the end position for line, right before the newline</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">6</span><span class="p">,</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">end_pos</span><span class="w">
</span><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">''</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">end_pos</span><span class="w">
</span><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'1'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">end_pos</span></code></pre>


<h4 id=".has_eol-is-true-if-the-line-has-an-eol">.has_eol is true if the line has an EOL</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'one\ntwo'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">has_eol</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">has_eol</span></code></pre>


<h4 id=".byte_start_pos-returns-the-byte-start-position-for-line">.byte_start_pos returns the byte start position for line</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'åäö\nwØrld'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">byte_start_pos</span><span class="p">,</span><span class="w"> </span><span class="mi">8</span><span class="w">
</span><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">''</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">byte_start_pos</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span></code></pre>


<h4 id=".byte_end_pos-returns-the-byte-end-position-for-line">.byte_end_pos returns the byte end position for line</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'åäö\nwØrld'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">7</span><span class="p">,</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">byte_end_pos</span><span class="w">
</span><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">''</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">byte_end_pos</span><span class="w">
</span><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'1'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">byte_end_pos</span></code></pre>


<h4 id=".previous-returns-the-line-above-this-one,-or-nil-if-none">.previous returns the line above this one, or nil if none</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">previous</span><span class="p">,</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">previous</span></code></pre>


<h4 id=".previous_non_blank-returns-the-first-preceding-non-blank-line,-or-nil-if-none">.previous_non_blank returns the first preceding non-blank line, or nil if none</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">previous_non_blank</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">previous_non_blank</span><span class="w">
</span><span class="n">lines</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="s1">''</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">4</span><span class="p">].</span><span class="n">previous_non_blank</span></code></pre>


<h4 id=".previous_blank-returns-the-first-preceding-blank-line,-or-nil-if-none">.previous_blank returns the first preceding blank line, or nil if none</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'one\n\nthree\nfour'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">previous_blank</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">3</span><span class="p">].</span><span class="n">previous_blank</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">4</span><span class="p">].</span><span class="n">previous_blank</span></code></pre>


<h4 id=".next-returns-the-line-below-this-one,-or-nil-if-none">.next returns the line below this one, or nil if none</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="nb">next</span><span class="p">,</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">3</span><span class="p">].</span><span class="nb">next</span></code></pre>


<h4 id=".next_non_blank-returns-the-first-succeding-non-blank-line,-or-nil-if-none">.next_non_blank returns the first succeding non-blank line, or nil if none</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">3</span><span class="p">].</span><span class="n">next_non_blank</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">3</span><span class="p">],</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">next_non_blank</span><span class="w">
</span><span class="n">lines</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="s1">''</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">4</span><span class="p">],</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">next_non_blank</span></code></pre>


<h4 id=".next_blank-returns-the-first-succeding-blank-line,-or-nil-if-none">.next_blank returns the first succeding blank line, or nil if none</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'one\n\nthree\nfour'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">3</span><span class="p">].</span><span class="n">next_blank</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">next_blank</span></code></pre>


<h4 id=".indent()-indents-the-line-by-&lt;config.indent&gt;">.indent() indents the line by &lt;config.indent&gt;</h4>

<pre class="highlight moonscript"><code><span class="n">config</span><span class="p">.</span><span class="n">indent</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">buf</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">\</span><span class="n">indent</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'  hƏllØ\n  wØrld\nagain!'</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w">

</span><span class="n">buf</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">indent</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">buf</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span><span class="o">\</span><span class="n">indent</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'  hƏllØ\n  wØrld\n again!'</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id="#line-returns-the-length-of-the-line">#line returns the length of the line</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'åäö'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="o">#</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="mi">3</span></code></pre>


<h4 id="lines-are-equal-if-they-have-the-same-text">lines are equal if they have the same text</h4>

<pre class="highlight moonscript"><code><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllØ'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span></code></pre>


<h4 id="string-methods-can-be-accessed-directly-on-the-object">string methods can be accessed directly on the object</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'first line'</span><span class="w">
</span><span class="n">line</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'fi'</span><span class="p">,</span><span class="w"> </span><span class="n">line</span><span class="o">\</span><span class="n">sub</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">8</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">line</span><span class="o">\</span><span class="n">find</span><span class="p">(</span><span class="s1">'in'</span><span class="p">))</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'first win'</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">line</span><span class="o">\</span><span class="n">gsub</span><span class="p">(</span><span class="s1">'line'</span><span class="p">,</span><span class="w"> </span><span class="s1">'win'</span><span class="p">))</span></code></pre>


<h4 id="string-properties-can-be-accessed-directly-on-the-object">string properties can be accessed directly on the object</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">is_empty</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">is_blank</span><span class="w">
</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">''</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">is_empty</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">is_blank</span></code></pre>

<div class="spec-group spec-group-3">

<h3 id=".text-=-&lt;content&gt;">.text = &lt;content&gt;</h3>

<h4 id="replaces-the-line-text-with-&lt;content&gt;">replaces the line text with &lt;content&gt;</h4>

<pre class="highlight moonscript"><code><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'Hola'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'Hola\n  wØrld\nagain!'</span></code></pre>


<h4 id="raises-an-error-if-&lt;content&gt;-is-nil">raises an error if &lt;content&gt; is nil</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'nil'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span></code></pre>

</div>
<div class="spec-group spec-group-3">

<h3 id=".indentation">.indentation</h3>

<h4 id=".indentation-returns-the-indentation-for-the-line">.indentation returns the indentation for the line</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">indentation</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">indentation</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span></code></pre>


<h4 id="respects-the-configured-tab_width-for-tabs">respects the configured tab_width for tabs</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'\tfirst\n  \tsecond'</span><span class="w">
</span><span class="n">lines</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">lines</span><span class="w">
</span><span class="n">buf</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">tab_width</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">3</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">indentation</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">indentation</span></code></pre>

</div>
<div class="spec-group spec-group-3">

<h3 id=".indentation-=-&lt;nr&gt;">.indentation = &lt;nr&gt;</h3>

<h4 id="works-for-empty-lines">works for empty lines</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'first\n'</span><span class="w">
</span><span class="n">lines</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">lines</span><span class="w">
</span><span class="n">buf</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">use_tabs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span><span class="w">
</span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">indentation</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'first\n  '</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">text</span></code></pre>

<div class="spec-group spec-group-4">

<h3 id="(when-`use_tabs`-is-false)">(when `use_tabs` is false)</h3>

<h4 id="set-the-indentation-for-the-line-to-&lt;nr&gt;-spaces">set the indentation for the line to &lt;nr&gt; spaces</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'first\n'</span><span class="w">
</span><span class="n">lines</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">lines</span><span class="w">
</span><span class="n">buf</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">use_tabs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span><span class="w">
</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">indentation</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">8</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'        first\n'</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
<div class="spec-group spec-group-4">

<h3 id="(when-`use_tabs`-is-true)">(when `use_tabs` is true)</h3>

<pre class="highlight moonscript"><code><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">buf</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">use_tabs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">true</span><span class="w">
  </span><span class="n">buf</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">tab_width</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">4</span></code></pre>


<h4 id="squeezes-in-as-many-tabs-as-possible">squeezes in as many tabs as possible</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'first\nsecond'</span><span class="w">
</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">indentation</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">5</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'\t first'</span><span class="p">,</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">text</span><span class="w">
</span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">indentation</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">8</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'\t\tsecond'</span><span class="p">,</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">text</span></code></pre>


<h4 id="handles-lines-with-existing-tabs">handles lines with existing tabs</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'\tx'</span><span class="w">
</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">indentation</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">8</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'\t\tx'</span><span class="p">,</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">text</span></code></pre>

</div>
<div class="spec-group spec-group-4">

<h3 id="(when-markers-are-present-in-the-intentation)">(when markers are present in the intentation)</h3>

<h4 id="preserves-and-shifts-markers">preserves and shifts markers</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'    abc\n'</span><span class="w">
</span><span class="n">buf</span><span class="p">.</span><span class="n">markers</span><span class="o">\</span><span class="n">add</span><span class="w"> </span><span class="p">{{</span><span class="w">
  </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'test'</span><span class="w">
  </span><span class="ss">start_offset:</span><span class="w"> </span><span class="mi">3</span><span class="w">
  </span><span class="ss">end_offset:</span><span class="w"> </span><span class="mi">5</span><span class="w">
</span><span class="p">}}</span><span class="w">

</span><span class="n">line</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="w">

</span><span class="n">line</span><span class="p">.</span><span class="n">indentation</span><span class="w"> </span><span class="o">-=</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{{</span><span class="ss">name:</span><span class="w"> </span><span class="s1">'test'</span><span class="p">,</span><span class="w"> </span><span class="ss">start_offset:</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="ss">end_offset:</span><span class="w"> </span><span class="mi">4</span><span class="p">}},</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">markers</span><span class="o">\</span><span class="n">for_range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">buf</span><span class="p">)</span><span class="w">

</span><span class="n">line</span><span class="p">.</span><span class="n">indentation</span><span class="w"> </span><span class="o">-=</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{{</span><span class="ss">name:</span><span class="w"> </span><span class="s1">'test'</span><span class="p">,</span><span class="w"> </span><span class="ss">start_offset:</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="ss">end_offset:</span><span class="w"> </span><span class="mi">3</span><span class="p">}},</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">markers</span><span class="o">\</span><span class="n">for_range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">buf</span><span class="p">)</span><span class="w">

</span><span class="n">line</span><span class="p">.</span><span class="n">indentation</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{{</span><span class="ss">name:</span><span class="w"> </span><span class="s1">'test'</span><span class="p">,</span><span class="w"> </span><span class="ss">start_offset:</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="ss">end_offset:</span><span class="w"> </span><span class="mi">5</span><span class="p">}},</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">markers</span><span class="o">\</span><span class="n">for_range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">buf</span><span class="p">)</span></code></pre>

</div>
</div>
<div class="spec-group spec-group-3">

<h3 id=".chunk">.chunk</h3>

<h4 id="a-chunk-object-for-the-line,-disregarding-the-newline">a Chunk object for the line, disregarding the newline</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hƏllØ\nbare'</span><span class="w">
</span><span class="n">chunk</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">chunk</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'Chunk'</span><span class="p">,</span><span class="w"> </span><span class="n">typeof</span><span class="w"> </span><span class="n">chunk</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hƏllØ'</span><span class="p">,</span><span class="w"> </span><span class="n">chunk</span><span class="p">.</span><span class="n">text</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">chunk</span><span class="p">.</span><span class="n">start_pos</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="n">chunk</span><span class="p">.</span><span class="n">end_pos</span><span class="w">

</span><span class="n">chunk</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">chunk</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'bare'</span><span class="p">,</span><span class="w"> </span><span class="n">chunk</span><span class="p">.</span><span class="n">text</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">7</span><span class="p">,</span><span class="w"> </span><span class="n">chunk</span><span class="p">.</span><span class="n">start_pos</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">10</span><span class="p">,</span><span class="w"> </span><span class="n">chunk</span><span class="p">.</span><span class="n">end_pos</span></code></pre>


<h4 id="respects-the-buffer-eol">respects the buffer eol</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'MORE\r\nDOS'</span><span class="w">
</span><span class="n">buf</span><span class="p">.</span><span class="n">eol</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'\r\n'</span><span class="w">
</span><span class="n">chunk</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">chunk</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'MORE'</span><span class="p">,</span><span class="w"> </span><span class="n">chunk</span><span class="p">.</span><span class="n">text</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">chunk</span><span class="p">.</span><span class="n">start_pos</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="n">chunk</span><span class="p">.</span><span class="n">end_pos</span></code></pre>


<h4 id="is-an-empty-chunk-for-empty-lines">is an empty chunk for empty lines</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'\n'</span><span class="w">
</span><span class="n">chunk</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">chunk</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">''</span><span class="p">,</span><span class="w"> </span><span class="n">chunk</span><span class="p">.</span><span class="n">text</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">chunk</span><span class="p">.</span><span class="n">start_pos</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="n">chunk</span><span class="p">.</span><span class="n">end_pos</span><span class="w">

</span><span class="n">chunk</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">chunk</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">''</span><span class="p">,</span><span class="w"> </span><span class="n">chunk</span><span class="p">.</span><span class="n">text</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="n">chunk</span><span class="p">.</span><span class="n">start_pos</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">chunk</span><span class="p">.</span><span class="n">end_pos</span></code></pre>

</div>
<div class="spec-group spec-group-3">

<h3 id="describe-.unindent()">describe .unindent()</h3>

<h4 id="unindents-the-line-by-&lt;config.indent&gt;">unindents the line by &lt;config.indent&gt;</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'  first\n  second'</span><span class="w">
</span><span class="n">config</span><span class="p">.</span><span class="n">indent</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">buf</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">\</span><span class="n">unindent</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'first\n  second'</span><span class="w">

</span><span class="n">buf</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">indent</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">buf</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">\</span><span class="n">unindent</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'first\n second'</span></code></pre>


<h4 id="unindents-back-to-a-valid-indentation-line-for-uneven-indents">unindents back to a valid indentation line for uneven indents</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'   first\n  second'</span><span class="w">
</span><span class="n">buf</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">indent</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">buf</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">\</span><span class="n">unindent</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'  first\n  second'</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id="unindents-back-to-zero-for-a-1-space-indent">unindents back to zero for a 1-space indent</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">' first\n  second'</span><span class="w">
</span><span class="n">buf</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">indent</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">buf</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">\</span><span class="n">unindent</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'first\n  second'</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
<div class="spec-group spec-group-3">

<h3 id="replace(i,-j,-replacement)">replace(i, j, replacement)</h3>

<h4 id="replaces-the-range-[i,j]-with-&lt;replacement&gt;">replaces the range [i,j] with &lt;replacement&gt;</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'123\n567'</span><span class="w">
</span><span class="n">buf</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">\</span><span class="n">replace</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="s1">'x'</span><span class="w">
</span><span class="n">buf</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">\</span><span class="n">replace</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'x'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'x23\nx7'</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id="works-with-character-offsets">works with character offsets</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'åäö'</span><span class="w">
</span><span class="n">buf</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">\</span><span class="n">replace</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="s1">'x'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'åxö'</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
<div class="spec-group spec-group-3">

<h3 id="real_column(column)">real_column(column)</h3>

<pre class="highlight moonscript"><code><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">buf</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">tab_width</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">4</span></code></pre>


<h4 id="returns-the-real-column-index-of-&lt;column&gt;,-accounting-for-tabs">returns the real column index of &lt;column&gt;, accounting for tabs</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'\tsome text'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">\</span><span class="n">real_column</span><span class="w"> </span><span class="mi">5</span></code></pre>


<h4 id="works-with-character-offsets">works with character offsets</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'åäö'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">\</span><span class="n">real_column</span><span class="w"> </span><span class="mi">2</span></code></pre>


<h4 id="handles-boundary-cases-correctly">handles boundary cases correctly</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'\t56'</span><span class="w">
</span><span class="n">line</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">line</span><span class="o">\</span><span class="n">real_column</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="n">line</span><span class="o">\</span><span class="n">real_column</span><span class="w"> </span><span class="mi">7</span></code></pre>


<h4 id="raises-an-error-for-out-of-bounds-&lt;column&gt;s">raises an error for out of bounds &lt;column&gt;s</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'\t56'</span><span class="w">
</span><span class="n">line</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'column'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">line</span><span class="o">\</span><span class="n">real_column</span><span class="w"> </span><span class="mi">0</span></code></pre>


<h4 id="returns-the-last-real-column-if-the-virtual-column-overshoots">returns the last real column if the virtual column overshoots</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'\t56'</span><span class="w">
</span><span class="n">line</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="n">line</span><span class="o">\</span><span class="n">real_column</span><span class="w"> </span><span class="mi">8</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="n">line</span><span class="o">\</span><span class="n">real_column</span><span class="w"> </span><span class="mi">9</span></code></pre>

</div>
<div class="spec-group spec-group-3">

<h3 id="virtual_column(column)">virtual_column(column)</h3>

<h4 id="returns-the-virtual-column,-accounting-for-tabs">returns the virtual column, accounting for tabs</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">tab_width</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">4</span><span class="w">
</span><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'\tsome text after'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">\</span><span class="n">virtual_column</span><span class="w"> </span><span class="mi">2</span></code></pre>


<h4 id="works-with-character-offsets">works with character offsets</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'åäö'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">\</span><span class="n">virtual_column</span><span class="w"> </span><span class="mi">2</span></code></pre>


<h4 id="handles-boundary-cases-correctly">handles boundary cases correctly</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'123'</span><span class="w">
</span><span class="n">line</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">line</span><span class="o">\</span><span class="n">virtual_column</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="n">line</span><span class="o">\</span><span class="n">virtual_column</span><span class="w"> </span><span class="mi">4</span></code></pre>


<h4 id="raises-an-error-for-out-of-bounds-&lt;column&gt;s">raises an error for out of bounds &lt;column&gt;s</h4>

<pre class="highlight moonscript"><code><span class="n">buf</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'123'</span><span class="w">
</span><span class="n">line</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buf</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'column'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">line</span><span class="o">\</span><span class="n">virtual_column</span><span class="w"> </span><span class="mi">0</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'column'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">line</span><span class="o">\</span><span class="n">virtual_column</span><span class="w"> </span><span class="mi">5</span></code></pre>

</div>
</div>
<div class="spec-group spec-group-2">

<h2 id="[nr]">[nr]</h2>

<h4 id="returns-a-line-object-for-the-specified-line">returns a line object for the specified line</h4>

<pre class="highlight moonscript"><code><span class="n">lines</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="p">(</span><span class="s1">'hello\n  world\nagain!'</span><span class="p">).</span><span class="n">lines</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'hello'</span></code></pre>


<h4 id="returns-nil-if-the-line-number-is-invalid">returns nil if the line number is invalid</h4>

<pre class="highlight moonscript"><code><span class="n">lines</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="p">(</span><span class="s1">'hello!'</span><span class="p">).</span><span class="n">lines</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span></code></pre>

</div>
<div class="spec-group spec-group-2">

<h2 id="[nr]-=-&lt;value&gt;">[nr] = &lt;value&gt;</h2>

<h4 id="replaces-the-text-of-the-specified-line-with-&lt;value&gt;">replaces the text of the specified line with &lt;value&gt;</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'hellØ\nwØrld'</span><span class="w">
</span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hØla'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'hØla\nwØrld'</span></code></pre>


<h4 id="removes-the-entire-line-if-value-is-nil">removes the entire line if value is nil</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'gØØdbye\ncruel\nwØrld'</span><span class="w">
</span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'gØØdbye\nwØrld'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="w">
</span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'wØrld'</span><span class="w"> </span><span class="p">,</span><span class="n">b</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id="raises-an-error-if-the-line-number-is-invalid">raises an error if the line number is invalid</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'hello!'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'Invalid index'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="s1">'foo'</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'bar'</span></code></pre>

</div>
<div class="spec-group spec-group-2">

<h2 id="delete(start,-end)">delete(start, end)</h2>

<h4 id="deletes-the-the-lines-[start,-end]">deletes the the lines [start, end]</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'hellØ\nwØrld\nagain!'</span><span class="w">
</span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="o">\</span><span class="n">delete</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'again!'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id="for-end-&lt;-start-it-does-nothing">for end &lt; start it does nothing</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'hellØ'</span><span class="w">
</span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="o">\</span><span class="n">delete</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hellØ'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span></code></pre>


<h4 id="deletes-up-to-the-last-line-if-end-&gt;-nr-lines">deletes up to the last line if end &gt; nr lines</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'hellØ\nwØrld\nagain!'</span><span class="w">
</span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="o">\</span><span class="n">delete</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">6</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hellØ\n'</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span></code></pre>

</div>
<div class="spec-group spec-group-2">

<h2 id="range(start,-end)">range(start, end)</h2>

<h4 id="returns-a-table-with-lines-[start,-end]">returns a table with lines [start, end]</h4>

<pre class="highlight moonscript"><code><span class="n">lines</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="p">(</span><span class="s1">'one\ntwo\nthree'</span><span class="p">).</span><span class="n">lines</span><span class="w">
</span><span class="n">range</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">lines</span><span class="o">\</span><span class="n">range</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">range</span></code></pre>


<h4 id="start-can-be-greater-than-end">start can be greater than end</h4>

<pre class="highlight moonscript"><code><span class="n">lines</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="p">(</span><span class="s1">'one\ntwo\nthree'</span><span class="p">).</span><span class="n">lines</span><span class="w">
</span><span class="n">range</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">lines</span><span class="o">\</span><span class="n">range</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">range</span></code></pre>

</div>
<div class="spec-group spec-group-2">

<h2 id="for_text_range(start_pos,-end_pos)">for_text_range(start_pos, end_pos)</h2>

<h4 id="returns-a-table-with-lines-between-[start_pos,-end_pos]">returns a table with lines between [start_pos, end_pos]</h4>

<pre class="highlight moonscript"><code><span class="n">lines</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="p">(</span><span class="s1">'one\ntwo\nthree'</span><span class="p">).</span><span class="n">lines</span><span class="w">
</span><span class="n">range</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">lines</span><span class="o">\</span><span class="n">for_text_range</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">6</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">range</span></code></pre>


<h4 id="start_pos-can-be-greater-than-end_pos">start_pos can be greater than end_pos</h4>

<pre class="highlight moonscript"><code><span class="n">lines</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="p">(</span><span class="s1">'one\ntwo\nthree'</span><span class="p">).</span><span class="n">lines</span><span class="w">
</span><span class="n">range</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">lines</span><span class="o">\</span><span class="n">for_text_range</span><span class="w"> </span><span class="mi">6</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">range</span></code></pre>


<h4 id="does-not-include-lines-only-touched-at-the-start-positions">does not include lines only touched at the start positions</h4>

<pre class="highlight moonscript"><code><span class="n">lines</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="p">(</span><span class="s1">'one\ntwo\nthree'</span><span class="p">).</span><span class="n">lines</span><span class="w">
</span><span class="n">range</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">lines</span><span class="o">\</span><span class="n">for_text_range</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">end_pos</span><span class="p">,</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">3</span><span class="p">].</span><span class="n">start_pos</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">range</span></code></pre>

</div>
<div class="spec-group spec-group-2">

<h2 id="append(text)">append(text)</h2>

<h4 id="append(text)-appends-&lt;text&gt;-with-the-necessary-newlines">append(text) appends &lt;text&gt; with the necessary newlines</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'one\ntwo'</span><span class="w">
</span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="o">\</span><span class="n">append</span><span class="w"> </span><span class="s1">'three'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'one\ntwo\nthree\n'</span><span class="w">

</span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'one\ntwo\n'</span><span class="w">
</span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="o">\</span><span class="n">append</span><span class="w"> </span><span class="s1">'three'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'one\ntwo\nthree\n'</span></code></pre>


<h4 id="returns-a-line-object-for-the-newly-appended-line">returns a line object for the newly appended line</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'line'</span><span class="w">
</span><span class="n">line</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="o">\</span><span class="n">append</span><span class="w"> </span><span class="s1">'omega'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">line</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span></code></pre>

</div>
<div class="spec-group spec-group-2">

<h2 id="insert(line_nr,-text)">insert(line_nr, text)</h2>

<h4 id="inserts-a-new-line-at-&lt;nr&gt;-with-&lt;text&gt;">inserts a new line at &lt;nr&gt; with &lt;text&gt;</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'one\ntwo'</span><span class="w">
</span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'half'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'half\none\ntwo'</span><span class="w">

</span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="s1">'1.5'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'half\none\n1.5\ntwo'</span></code></pre>


<h4 id="appends-the-line-if-line_nr-is-just-beyond-the-last-line">appends the line if line_nr is just beyond the last line</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'first\nsecond'</span><span class="w">
</span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="s1">'first\nsecond\nfoo\n'</span></code></pre>


<h4 id="raises-an-error-if-&lt;line_nr&gt;-is-invalid">raises an error if &lt;line_nr&gt; is invalid</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'first\nsecond'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'Invalid'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'Invalid'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="s1">'foo'</span></code></pre>


<h4 id="returns-a-line-object-for-the-newly-inserted-line">returns a line object for the newly inserted line</h4>

<pre class="highlight moonscript"><code><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="s1">'line'</span><span class="w">
</span><span class="n">line</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="o">\</span><span class="n">insert</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'alpha'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">line</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span></code></pre>

</div>
</div>
